import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { RxjsComponent } from './rxjs/rxjs.component';
import { HomeComponent } from './home/home.component';
import { ErrorComponent } from './error/error.component';
import { RouterComponent } from './router/router.component';
import { Page1Component } from './router/page1/page1.component';
import { Page2Component } from './router/page2/page2.component'
import {LazyComponent} from "./lazy/lazy.component";
import {AuthGuard} from "./guards/auth.guard";
import {AuthChildGuard} from "./guards/auth-child.guard";
import {LeaveGuard} from "./guards/leave.guard";
import {AsyncResolver} from "./guards/async.resolver";
import {BasicComponent} from "./basic/basic.component";
import {DirectiveComponent} from "./directive/directive.component";
import {PageAComponent} from "./page-a/page-a.component";
import {PageBComponent} from "./page-b/page-b.component";
import {NgRxComponent} from "./ng-rx/ng-rx.component";
import {MyrxjsComponent} from "./myrxjs/myrxjs.component";

const routes: Routes = [
  {
    path: "rxjs",
    component: RxjsComponent
  },
  {
    path: "home",
    component: HomeComponent
  }, {
    path: "router",
    component: RouterComponent,
    canActivate: [AuthGuard],
    canActivateChild: [AuthChildGuard],
    canDeactivate: [LeaveGuard],
    resolve: {
      user: AsyncResolver
    },
    children: [
      {
        path: "page1",
        component: Page1Component,
        outlet: "left"
      },
      {
        path: "page2",
        component: Page2Component,
        outlet: "right"
      }
    ]
  },
  {
    path: "lazy",
    component: LazyComponent,
  },
  {
    path: "ng-rx",
    component: NgRxComponent,
  },
  {
    path: "lazy",
    loadChildren: () => import("./lazy/lazy.module").then(m => m.LazyModule)
  },
  {
    path: "basic",
    component: BasicComponent,
  },
  {
    path: "directive",
    component: DirectiveComponent,
  },
  {
    path: "myrxjs",
    component: MyrxjsComponent,
  },
  {
    path: "",
    // 重定向
    redirectTo: "home",
    // 完全匹配
    pathMatch: "full"
  }, {
    path: "**",
    component: ErrorComponent
  }
]
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }
